#include "stdafx.h"
#include "UserDataLua.h"
#include "UserDataScene.h"
#include "Message/MsgScene.h"
#include "Lua/LuaWrapper.h"


int lua_c_enter_district(lua_State* l)
{
	if (lua_gettop(l)>=2)
	{
		MsgEnterDistrictRequest* pMsg = new MsgEnterDistrictRequest;
		pMsg->cid = (char)luaL_checkint(l, 1);
		pMsg->did = (char)luaL_checkint(l, 2);
		UserDataLua::instance()->wpSvcNet->postMsg(pMsg);
	}
	else
	{
		LOG_ERROR("LuaC, function scene.enterD lack of parameter: cid, did");
	}
	return 0;
}


int lua_c_enter_scene(lua_State* l)
{
	if (lua_gettop(l)>=3)
	{
		MsgEnterSceneRequest* pMsg = new MsgEnterSceneRequest;
		pMsg->cid = (char)luaL_checkint(l, 1);
		pMsg->did = (char)luaL_checkint(l, 2);
		pMsg->sid = (char)luaL_checkint(l, 3);
		UserDataLua::instance()->wpSvcNet->postMsg(pMsg);
	}
	else
	{
		LOG_ERROR("LuaC, function scene.enterS lack of parameter: cid, did, sid");
	}
	return 0;
}

int lua_c_combat_start(lua_State* l)
{
	if (lua_gettop(l)>=2)
	{
		MsgCombatStartRequest* pMsg = new MsgCombatStartRequest;
		pMsg->dsid = (char)luaL_checkint(l, 1);
		pMsg->wid = (char)luaL_checkint(l, 2);
		UserDataLua::instance()->wpSvcNet->postMsg(pMsg);
	}
	else
	{
		LOG_ERROR("LuaC, function scene.combatStart lack of parameter: dsid, wid");
	}
	return 0;
}


int lua_c_combat_end(lua_State* l)
{
	if (lua_gettop(l)>=1)
	{
		MsgCombatEndRequest* pMsg = new MsgCombatEndRequest;
		pMsg->dsid = (char)luaL_checkint(l, 1);
		UserDataLua::instance()->wpSvcNet->postMsg(pMsg);
	}
	else
	{
		LOG_ERROR("LuaC, function scene.combatEnd lack of parameter: dsid");
	}
	return 0;
}

static const luaL_Reg scene_funcs[] = {
	{"enterDisctrict", lua_c_enter_district},
	{"enterScene", lua_c_enter_scene},
	{"enterD", lua_c_enter_district},
	{"enterS", lua_c_enter_scene},
	{"combatStart", lua_c_combat_start},
	{"combatEnd", lua_c_combat_start},
	{NULL, NULL}
};


void initializeSceneLua()
{
	Lua::instance()->load("scene", scene_funcs);
}
